package metalink;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.sql.*;

import org.apache.struts2.ServletActionContext;

import vo.*;
import vo.mixed.*;
import model.admin.*;
import myutil.*;


public class ReadMessage extends ActionSupport {
int message_id;

public int getMessage_id() {
	return message_id;
}

public void setMessage_id(int message_id) {
	this.message_id = message_id;
}
String body;
ArrayList<String> attachments=new ArrayList<String>();
int attachment_id=0;
public ArrayList<String> getAttachments() {
	return attachments;
}

public void setAttachments(ArrayList<String> attachments) {
	this.attachments = attachments;
}

public int getAttachment_id() {
	return attachment_id;
}

public void setAttachment_id(int attachment_id) {
	this.attachment_id = attachment_id;
}

public String getBody() {
	return body;
}

public void setBody(String body) {
	this.body = body;
}

public String execute(){
	String username;
	Connect c;
	
	try {
		username = ServletActionContext.getRequest().getSession().getAttribute("username").toString();
		System.out.println("i came here");
		c = new Connect();
		c.dml("update message_receiver set read_flag=1 where message_id='"+message_id+"' and receiver_id='"+username+"'");
       // MessageVo message=new MessageVo();
        ResultSet rs=c.getResult("select * From message where message_id='"+message_id+"'");
        if(rs.next()){
        	body=(rs.getString("body"));
        
        if(rs.getInt("attachment_id")!=0){
        	attachment_id=rs.getInt("attachment_id");
        	rs=c.getResult("select * From document_upload where document_id='"+attachment_id+"'");
        	if(rs.next()){
        		String filename=rs.getString("document_name");
        		attachments.add(filename);
        	}
        }
        }
        
        return SUCCESS;
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return ERROR;
	}
	
}
}
